﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TrackingSim.GameSystem.Events
{
    static class GameEventManager
    {
        static Dictionary<GameEventType, List<GameObject>> event_map;

        static GameEventManager()
        {
            event_map = new Dictionary<GameEventType, List<GameObject>>();
        }

        public static void registerForEvent( GameObject gameObject, GameEvent _event )
        {
            if(!event_map.ContainsKey(_event.getType() ) )
            {
                event_map.Add(_event.getType(), new List<GameObject>());
            }

            event_map[_event.getType()].Add(gameObject);
        }

        public static void unregisterForEvent(GameObject gameObject, GameEvent _event)
        {
            if( event_map.ContainsKey(_event.getType() ) )
            {
                if (event_map[_event.getType()].Contains(gameObject))
                {
                    event_map[_event.getType()].Remove(gameObject);
                }
            }
        }

        public static void notifyObservers(GameEvent _event)
        {
            if( event_map.ContainsKey(_event.getType() ))
            {
                foreach( IGameEventObserver o in event_map[_event.getType()] )
                {
                    o.receiveEvent(_event);
                }
            }
        }
    }
}
